package com.vivimice.lotroller.demo;

import com.vivimice.lotroller.notification.NotificationAgent;
import com.vivimice.lotroller.notification.NotificationType;
import com.vivimice.lotroller.notification.SynchronizedNotificationAgent;

public class DemoApp {

	public static NotificationType APP_START;
	
	static {
		NotificationType.doAutoNaming(DemoApp.class);
	}
	
	private void run() throws Exception {
		
		/////////////////////////////////////
		// Initialization and preparation
		/////////////////////////////////////
		
		// Create a thread-safe notification agent as messaging bus
		NotificationAgent agent = new SynchronizedNotificationAgent();
		// init components
		DemoNetworkingEmulator demoNetworkingEmulator = new DemoNetworkingEmulator(agent);
		DemoFileSystemEmulator demoFileSystemEmulator = new DemoFileSystemEmulator(agent);
		new DemoUI(agent);
		// init lotroller, which contains all inter-component controll logic
		DemoLotroller demoLotroller = new DemoLotroller(agent);
		
		/////////////////////////////////////
		// Starts application
		/////////////////////////////////////
		agent.sendNotification(APP_START);
			
		/////////////////////////////////////
		// Exit
		/////////////////////////////////////
		// wait for network/fs thread to quit
		demoNetworkingEmulator.join();
		demoFileSystemEmulator.join();
		demoLotroller.close();
	}
	
	public static void main(String[] args) throws Exception {
		new DemoApp().run();
	}
	
}
